package com.salt.admin.api.model;

import com.salt.admin.api.persistence.DataEntity;
import com.salt.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Arrays;
import java.util.List;

/**
 * @Description 管理用户的租户权限（即查看多个公司的数据）
 * @Author salt
 * @Date 2022/1/19
 * @Version 1.0.1
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class MultiTenant extends DataEntity<MultiTenant> {

    private User user;
    private String tenants;  // 用逗号隔开
    private List<Office> tenantList;

    private List<String> tenantIds;
    

    public MultiTenant(User user) {
        super();
        this.user = user;
    }

    public List<String> getTenantIds() {
        if (StringUtils.isNotBlank(this.tenants)) {
            String[] split = this.tenants.split(",");
            return Arrays.asList(split);
        }
        return null;
    }

    public Boolean isTenant() {
        return this.user != null ? true : false;
    }

}
